package a1;

import com.common.ChannelInitializer;
import com.common.ChannelPipeline;
import com.common.CharsetUtil;
import com.common.SocketChannel;
import com.common.StringDecoder;
import com.common.StringEncoder;
import com.common.http.LengthFieldBasedFrameDecoder;
import com.common.http.LengthFieldPrepender;

public class MyClientInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
        pipeline.addLast(new LengthFieldPrepender(4));
        pipeline.addLast(new StringDecoder(CharsetUtil.UTF_8));
        pipeline.addLast(new StringEncoder(CharsetUtil.UTF_8));
        pipeline.addLast(new MyClientHandler());
    }
}
